<?php
/**
 * ActiveRecord is the customized base active record class.
 * All active record classes for this application should extend from this base
 * class.
 */
class ActiveRecord extends CActiveRecord {
	/**
	 * Checks if the given value is empty. A value is considered empty if it is
	 * null, an empty array, or the trimmed result is an empty string. Note that
	 * this method is different from PHP empty(). It will return false when the
	 * value is 0.
	 * @param mixed $value
	 * @param boolean $trim
	 */
	protected function isEmpty($value, $trim=false) {
		return $value===null || $value===array() || $value==='' ||
			$trim && is_scalar($value) && trim($value)==='';
	}
	
	/**
	 * Returns the dot seperated named attribute value.
	 * @param string $name
	 */
	public function getAttribute($name) {
		if (strpos($name, '.') !== false) {
			$names = explode('.', $name);
			$value = $this;
			foreach ($names as $name) $value = $value->{$name};
			return $value;
		}
		else return parent::getAttribute($name);
	}
}
